package org.example.dao;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.example.entity.User;
import org.springframework.stereotype.Repository;

@Mapper
@Repository
public interface ShopDao {

    @Select("select * from user where account = #{account}")
    User selectUserByAccount(String account);

    @Insert("INSERT INTO user (id, username,account, password, email, mobile) " +
            "values (#{userId}, #{username}, #{account}, #{password}, #{email}, #{mobile})")
    void addUser(User userInfo);

    @Select("select * from user where username = #{username}")
    User selectUserByUsername(@Param(value="username") String username);

    @Select("select password from user where account = #{account}")
    String getPwdByAccount(String account);

    @Select("select * from user where email = #{email}")
    User selectUserByEmail(@Param(value = "email") String email);

    @Select("select * from user where mobile = #{mobile}")
    User selectUserByMobile(@Param(value = "mobile") String mobile);

    @Select("select * from user where email = #{email}")
    User useEmail(@Param(value = "email") String email);

    @Select("select * from user where mobile = #{mobile}")
    User useMobile(@Param(value = "mobile") String mobile);

    // 修改密码
    @Select("update user set password = #{password} where account = #{account}")
    void editPassword(@Param(value = "account") String account,@Param(value = "password") String password);
}
